import 'package:flutter/material.dart';

class MyButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('MyButton'), actions: [
        IconButton(
          icon: Icon(Icons.settings, color: Colors.white),
        )
      ]),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        backgroundColor: Colors.yellow,
        onPressed: () {
          print('floatingActionButton');
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      body: ListView(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              RaisedButton(
                child: Text('普通按钮'),
                onPressed: () {
                  print('普通按钮');
                },
              ),
              RaisedButton(
                child: Text('有颜色按钮'),
                textColor: Colors.white,
                color: Colors.blue,
                onPressed: () {
                  print('有颜色按钮');
                },
              ),
              RaisedButton(
                child: Text('有阴影按钮'),
                textColor: Colors.white,
                color: Colors.blue,
                elevation: 10.0,
                onPressed: () {
                  print('有阴影按钮');
                },
              ),
            ],
          ),
          SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Container(
                width: 150,
                height: 50,
                child: RaisedButton(
                  child: Text('设置宽高按钮'),
                  textColor: Colors.white,
                  color: Colors.blue,
                  elevation: 10.0,
                  onPressed: () {
                    print('设置宽高按钮');
                  },
                ),
              ),
            ],
          ),
          SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              Expanded(
                child: Container(
                  height: 60,
                  margin: EdgeInsets.all(20),
                  child: RaisedButton(
                    child: Text('设置宽高按钮'),
                    textColor: Colors.white,
                    color: Colors.blue,
                    elevation: 10.0,
                    onPressed: () {
                      print('设置宽高按钮');
                    },
                  ),
                ),
              ),
            ],
          ),
          SizedBox(height: 20),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              RaisedButton.icon(
                  textColor: Colors.white,
                  color: Colors.blue,
                  icon: Icon(Icons.search),
                  label: Text('有图标按钮'),
                  onPressed: () {
                    print('有图标按钮');
                  }),
              RaisedButton(
                  textColor: Colors.white,
                  color: Colors.blue,
                  child: Text('圆角按钮'),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(20)),
                  onPressed: () {
                    print('圆角按钮');
                  }),
              Container(
                height: 80,
                child: RaisedButton(
                    textColor: Colors.white,
                    color: Colors.blue,
                    splashColor: Colors.red,
                    child: Text('圆形按钮'),
                    shape: CircleBorder(
                        side: BorderSide(
                      color: Colors.blue,
                    )),
                    onPressed: () {
                      print('圆形按钮');
                    }),
              ),
            ],
          ),
          SizedBox(height: 20),
          Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
            FlatButton(
                color: Colors.blue,
                textColor: Colors.white,
                child: Text('扁平化按钮'),
//              shape:
                onPressed: () {
                  print('扁平化按钮');
                }),
          ]),
          SizedBox(height: 20),
          Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
            OutlineButton(
                textColor: Colors.red,
                child: Text('线框按钮'),
                onPressed: () {
                  print('线框按钮');
                }),
            Container(
                height: 50,
                child: OutlineButton(
                    textColor: Colors.red,
                    child: Text('线框按钮'),
                    onPressed: () {
                      print('线框按钮');
                    })),
          ]),
          SizedBox(height: 20),
          Row(children: [
            Expanded(
              child: OutlineButton(
                  textColor: Colors.red,
                  child: Text('线框按钮'),
                  onPressed: () {
                    print('线框按钮');
                  }),
            )
          ]),
          SizedBox(height: 20),
          Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
            ButtonBar(children: [
              RaisedButton(
                  textColor: Colors.red,
                  child: Text('按钮组'),
                  onPressed: () {
                    print('按钮组');
                  }),
              RaisedButton(
                  textColor: Colors.red,
                  child: Text('按钮组'),
                  onPressed: () {
                    print('按钮组');
                  }),
            ])
          ]),
          SizedBox(height: 20),
          Row(children: [
            MyBtn(
              text: '123',
              width: 100.0,
              pressed: () {
                print('123');
              },
            )
          ]),
          SizedBox(height: 2000),
        ],
      ),
    );
  }
}

class MyBtn extends StatelessWidget {
  final String text;
  final pressed;
  final double width;
  final double height;

  MyBtn({this.text = '', this.pressed, this.width = 80.0, this.height = 30.0});

  @override
  Widget build(BuildContext context) {
    return Container(
        height: this.height,
        width: this.width,
        child: RaisedButton(
          child: Text(this.text),
          onPressed: this.pressed,
        ));
  }
}
